package com.nami.gate.process.upmsg;



import com.nami.gate.config.RpcConfig;
import com.nami.gate.middleware.mq.MqSender;
import com.nami.im.network.model.enums.protocol.CMDEnum;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * 描述：
 *
 * @Author: lbc
 * @Date: 2023-07-16 16:31
 * @email: 594599620@qq.com
 * @Description: keep coding
 */

@Slf4j
public class PackageProcessFactory {

    private MqSender sender;

    private final RpcConfig rpcConfig;

    private final Map<Byte, PacketProcessor> map = new HashMap<Byte, PacketProcessor>(256);

    public PackageProcessFactory(MqSender sender, RpcConfig rpcConfig) {
        this.sender = sender;
        this.rpcConfig = rpcConfig;
        this.init();
    }

    public void init() {
//        map.put(UpCMDEnum.LOGIN.getCode(), new LoginProcess(sender, rpcConfig));

//        map.put(UpCMDEnum.C2C.getCode(), new C2CProcess(sender, rpcConfig));
//        map.put(UpCMDEnum.C2G.getCode(), new C2GProcess(sender, rpcConfig));
//
//        map.put(UpCMDEnum.LOGOUT.getCode(), new LogoutProcess(sender, rpcConfig));
//        map.put(UpCMDEnum.QOS.getCode(), new QosProcess(sender, rpcConfig));

        map.put(CMDEnum.CONNECT.getCode(), new LoginProcess(sender, rpcConfig));
        map.put(CMDEnum.PINGREQ.getCode(), new PingProcess(sender, rpcConfig));

        map.put(CMDEnum.PUBLISH.getCode(), new PublishProcess(sender, rpcConfig));
        map.put(CMDEnum.PUBACK.getCode(), new PublishAckProcess(sender, rpcConfig));

//        map.put(PacketEnum.LOGINOUT.getCmd(), new LogoutProcess(producer, dubboProperty));
        log.info("[UpMsgProcessorFactory] init process...");
    }

    public PacketProcessor getMessageProcess(byte code) {
        return map.get(code);
    }


}
